import java.util.Scanner;

public class MainApp {
    private final Scanner scanner = new Scanner(System.in);
    private final FactoryPatternModule factoryModule = new FactoryPatternModule();
    private final StatePatternModule stateModule = new StatePatternModule(factoryModule);
    private final ObserverPatternModule observerModule = new ObserverPatternModule();
    private final StrategyPatternModule strategyModule = new StrategyPatternModule();
    private final CommandPatternModule commandModule = new CommandPatternModule(factoryModule);
    private final DecoratorPatternModule decoratorModule = new DecoratorPatternModule(factoryModule);
    private final SystemManagerModule systemManager = new SystemManagerModule();

    public static void main(String[] args) {
        MainApp app = new MainApp();
        app.run();
    }

    public void run() {
        System.out.println("===== 农业智能管理系统启动 =====");

        while (true) {
            System.out.println("\n===== 主菜单 =====");
            System.out.println("1. 农机设备管理");
            System.out.println("2. 农机状态管理");
            System.out.println("3. 农田环境监测");
            System.out.println("4. 智能路径规划");
            System.out.println("5. 任务执行控制");
            System.out.println("6. 农机功能扩展");
            System.out.println("7. 系统管理");
            System.out.println("8. 退出系统");
            System.out.print("请选择功能(1-8): ");

            int choice = scanner.nextInt();
            scanner.nextLine();  // 消耗换行符

            switch (choice) {
                case 1 -> factoryModule.execute();
                case 2 -> stateModule.execute();
                case 3 -> observerModule.execute();
                case 4 -> strategyModule.execute();
                case 5 -> commandModule.execute();
                case 6 -> decoratorModule.execute();
                case 7 -> systemManager.execute();
                case 8 -> {
                    System.out.println("系统已退出");
                    return;
                }
                default -> System.out.println("无效选择，请重新输入");
            }
        }
    }
}